/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package quanlysieuthi;

import DTO.CChiTietHoaDon;
import DTO.CHoaDon;
import DTO.CTon_Kho;
import java.sql.Timestamp;
import java.util.List;


public class CKiemTra {
    public static String user_name  = "admin";
    public static long user_id  = 1;
    public static String tenNhanVien ="";
    public static void addChiTietHoaDon(CChiTietHoaDon chitiet,List<CChiTietHoaDon> list){
        list.add(chitiet);
    }
    
    public static CHoaDon addHoaDon(String loaiPhieu,long nguoilapId,long nguoiGiaoId,
            long khachHang_Id,String ten,String diaChi,long kho_id,Timestamp ngaynhap){
        CHoaDon hoadon = new CHoaDon();
        hoadon.setKhachHangId(khachHang_Id);
        hoadon.setKhoId(kho_id);
        hoadon.setLoaiPhieu(loaiPhieu);
        hoadon.setNgayNhap(ngaynhap);
        hoadon.setNguoiGiaoId(nguoiGiaoId);
        hoadon.setNguoiLapId(nguoilapId);
        hoadon.setNguoiSua(CKiemTra.user_name);
        hoadon.setNguoiTao(CKiemTra.user_name);        
        return hoadon;
    }
    
    
    public static Boolean isKiemTraSoLuongNhap(CTon_Kho tkho,int Sl){
        if(tkho == null)
            return true;
        if(tkho.getTonToiDa() == 0 && tkho.getTonToiThieu() == 0){
            return true;
        }
        int tongSoLuong = Sl + tkho.getSoLuongNhap() - tkho.getSoLuongXuat();
        if(tongSoLuong > tkho.getTonToiDa()){
            return false;
        }
        return true;
    }
    
    public static Boolean isKiemTraSLNhapToiThieu(CTon_Kho tkho){
        if(tkho.getTonToiDa() == 0 && tkho.getTonToiThieu() == 0){
            return true;
        }
        int tongSoLuong = tkho.getSoLuongNhap() - tkho.getSoLuongXuat() + tkho.getTonDau();
        if(tongSoLuong <= tkho.getTonToiThieu()){
            return true;// duocphep nhap
        }
        return false;
    }
    
    public static String MaTuTang(String s){
        String rightstring = "";
        String strdk = "0123456789";
        String rs = "";
        int count = 0;
        System.out.println("chuoi truyen vao : " + s);
        for(int i = s.length()-1;i > 0;i--){
            String c = s.substring(i, i + 1);
            if(strdk.contains(c)){
                rightstring = c + rightstring;
                System.out.println("result : " + c);
                count++;
            }
            else
                break;
        }
         if (rightstring == "")
         {
            rightstring = "0";
            rs = s + 1;
         }
         else{
             System.out.println("chuoi da cat " + rightstring);
             long number = Long.parseLong(rightstring);
             
             number = number + 1;
             rs = String.format("%s", number);
             String temp = s.substring(0,s.length()-rightstring.length());
             for(int i = rs.length();i < count ;i++){
                 rs = "0" + rs;//them so khong dang truoc
             }
             rs = temp + rs;
         }
        return rs;
    }
    
}
